<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:xi="http://www.w3.org/2001/XInclude"
      xmlns:py="http://genshi.edgewall.org/">
  <xi:include href="master.html" />

  <?python
    import datetime
    from mnemoply.common_knowledge import day_captions
    from mnemoply import model

    day_of_week = range(0, 7)
  ?>

  <head>
    <title>Print timetable</title>
  </head>

  <body>
    <div py:for="office in offices">
      <h2>
        <span py:strip="True">Office</span>: ${office.title}
      </h2>

      <table class="maintable">
        <thead>
          <tr>
            <th>#</th>
            <th>#</th>
            <th py:for="i in range(1, 8)" py:content="day_captions[i]" />
          </tr>
        </thead>
        <loop py:for="classroom in model.Classroom.selectBy(office=office)" py:strip="True">
          <tr py:for="session in range(1, 6)">
            <th py:if="session == 1" rowspan="5" py:content="classroom.roomNumber" />
            <th py:content="session" />

            <loop py:for="i in day_of_week" py:strip="True">
              <?python
                lessons = classroom.getLessonsByDate(start_date + datetime.timedelta(days=i))
                cell_style = ""
                try:
                    all_lessons_for_session = [l for l in lessons if l.group.session == session]
                    lesson = all_lessons_for_session[0]
                    if len(all_lessons_for_session) > 1:
                        cell_style = "more_one"
                except:
                    lesson = None
              ?>
              <td py:if="lesson" class="${cell_style}">
                ${lesson.getStartTimeStr()}&ndash;${lesson.getEndTimeStr()} <br />
                <a href="/Group/${lesson.group.id}/">${lesson.group.getShortName()}</a> <br />
                ${lesson.group.cacheStudents}  <br />
                ${lesson.group.teacher.title}  <br />
              </td>
              <td py:if="not lesson">
                  <br />
                  <br />
                  <br />
                  <br />
              </td>
            </loop>
          </tr>
        </loop>
      </table>

    </div>

    <span>${ET(tg.back_widget())}</span>

  </body>
</html>
